/*
 * Project Name spring-boot-tools
 * File Name IgnoreProperties
 * Package Name com.huxiaosu.tools.common.auth.confingure
 * Create Time 2024/7/29
 * Create by name：liujie
 */
package com.huxiaosu.tools.common.auth.confingure;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Stream;

/**
 * Description
 *
 * @author liujie
 * @date 2024/7/29 10:31
 */
@Data
@ConfigurationProperties(prefix = "tools.security.ignore")
public class IgnoreProperties {
    private static final String TO_SYMBOL = "-->";
    /**是否启用过滤规则*/
    private boolean enabled = false;

    /**
     * 过滤规则
     */
    private List<String> filterRules = new LinkedList<>();

    public LinkedHashMap<String, String> getFilterChainDefinitionMap() {
        LinkedHashMap<String, String> staticFilterChain = new LinkedHashMap<>();
        this.filterRules.forEach(rule->{
            if(rule.split(TO_SYMBOL).length > 1) {
                Stream.of(rule.split(TO_SYMBOL)[0].trim().split(","))
                        .forEach(url -> staticFilterChain.put(url.trim(), rule.split(TO_SYMBOL)[1].trim()));
            }
        });

        return staticFilterChain;
    }
}